<html>

	<head>
		<meta charset="UTF-8">
		<title>打印销售单</title>
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/print.css">
		<script type="text/javascript" src="../../../JS/common.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
		<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
		<script type="text/javascript" src="../../../JS/finance.js"></script>
	</head>

	<body>
		<div id="printContent"></div>

	</body>
	<script type="text/javascript">
		var remote_data_url = "";
		var paramid = getID(); /*得到当前界面的id*/
		var printType = paramid.substr(0, 1);
		var id = paramid.substr(2); //获取所有的数据
		if(printType == "A") {
			remote_data_url = RemoteLinkAddress + '/logistics/originalorder/getaorder.do?IDS=' + id;
		}
		if(printType == "B") {
			remote_data_url = RemoteLinkAddress + '/logistics/salesorder/getborder.do?IDS=' + id;
		}
		$(document).ready(function(){
			loadRemote();
		});
		
		function pageprint() {
			if(confirm("是否打印")) {
				print();
			}
		}

		$(function() {
			var _num = $(".xx").html();
			var num = changeMoneyToChinese(_num);
			$(".dx").html(num);
		});

		function loadRemote() {
			$.ajax({
				type: "get",
				url: remote_data_url,
				dataType: "json",
				success: function(result) {
					console.log(result);
					CreateHTML(result, printType);
				}
			});
		} /*将服务器上的内容，根据对应的ID传入id为‘ff’的相应的input标记中*/

		///暂缺 分类打印
		function CreateHTML(_data, type) {
			var disPlaycontent = "";
			var content = "";
			var content_indx = 0;
			var tmpID = "";
			var tmpPrice = "";
			var tmpSum = 0;
			var tmpName = "";

			console.log("数据长度" + _data.length);
			for(var i = 0; i < _data.length; i++) {
				var rowdata = _data[i].rows;
				var totalSum = 0;
				for(var j = 0; j < rowdata.length; j++) {
					if(type == "A") {
						tmpPrice = rowdata[j].UNIT_PRICE;
						tmpSum = parseFloat(rowdata[j].UNIT_PRICE) * parseFloat(rowdata[j].AMOUNT);
						tmpName = rowdata[j].TRADE_NAME;
					} else {
						tmpPrice = rowdata[j].UNIT_PRICE;
						tmpSum = parseFloat(rowdata[j].UNIT_PRICE) * parseFloat(rowdata[j].AMOUNT);
						totalSum = totalSum + parseFloat(tmpSum);
					}
				}
				_data[i].LUMP_SUM=totalSum.toFixed(2);
				content = "<div class='div_print_info_portait PageNext' style='height:auto;margin-top:25px'> <h1 align = 'center'> 绵阳市高水农副产品批发有限公司配送中心 </h1> <h1 align = 'center' > 销售单</h1> <table cellspacing = '6'style = ' width:700px;margin-top: 10px;margin-left: 0px;margin-bottom: 10px;' ><tr><th width='20%'> 订单编号 </th> <td width='80%'><input type = 'text' value='" + _data[i].ORDER_NO + "'class = 'print_text_style'  style='width:100%'/ ></td> </tr> </table> <table cellpadding = '6'class = 'altrowstable printtable' ><tr ><th width = '15 % '> 片区 </th> <td width = '35 % ' > <input class = 'print_text_style'value = '" + _data[i].CUSTOMER_TYPE + "' > </input> </td> <th width = '15%'> 配送单位 </th> <td width = '35%'> <input class = 'print_text_style' value = '" + _data[i].CUSTOMER_NAME + "'> </input> </td> </tr> <tr><th> 配送时间 </th> <td ><input class = 'print_text_style' value = '" + _data[i].DISTRIBUTION_DATE + "' > </input> </td> </tr> </table> <table class = 'altrowstable printtable'id = 'SalesTable'style = 'margin-top: 0px;' ><tr ><th> 品名 </th> <th> 单位 </th> <th> 单价 </th> <th> 数量 </th> <th > 总价 </th> </tr> </table> <table class = 'altrowstable printtable'style = 'margin-top: 0px;' ><tr ><th width = '36%' > 人民币金额合计（小写） </th> <td width = '64%'  > <input class = 'print_text_style xx' value = '" + _data[i].LUMP_SUM + "'  > </input> </td> </tr> <tr><th> 人民币金额合计（大写） </th> <td class='dx'> <input class = 'print_text_style xx' value = '" + changeMoneyToChinese(_data[i].LUMP_SUM) + "'  > </input> </td> </tr> </table> <div style = 'float: left;margin-left: 10px;'> 付款人： <span> </span></div ><div style = 'position: absolute;left:600' > 收款人： <span> </span></div > </div>";
				// disPlaycontent = disPlaycontent + content;
				$("#printContent").append(content);
				content_indx = content_indx + 1;
				$("#SalesTable").attr("id", "SalesTable" + content_indx);
				var newTd = new Array();
				var rowdata = _data[i].rows;
				var s = document.getElementById("SalesTable" + content_indx);
				
				for(var j = 0; j < rowdata.length; j++) {
					if(type == "A") {
						tmpPrice = rowdata[j].UNIT_PRICE;
						tmpSum = parseFloat(rowdata[j].UNIT_PRICE) * parseFloat(rowdata[j].AMOUNT);
						tmpName = rowdata[j].TRADE_NAME;
					} else {
						console.log(rowdata[j]);
						tmpPrice = rowdata[j].UNIT_PRICE;
						console.log(tmpPrice);
						tmpSum = parseFloat(rowdata[j].UNIT_PRICE) * parseFloat(rowdata[j].AMOUNT);
						tmpSum = tmpSum.toFixed(2);
						totalSum = totalSum + parseFloat(tmpSum);
						tmpName = rowdata[j].INTERNAL_NAME;
					}
					var newTr = s.insertRow();

					newTd[0] = newTr.insertCell()
					if(tmpName != undefined)
						newTd[0].innerText = tmpName;

					newTd[1] = newTr.insertCell();
					if(rowdata[j].UNIT_NAME != undefined)
						newTd[1].innerText = rowdata[j].UNIT_NAME;

					newTd[2] = newTr.insertCell();
					if(tmpPrice != undefined)
						newTd[2].innerText = tmpPrice;

					newTd[3] = newTr.insertCell();
					if(rowdata[j].AMOUNT != undefined)
						newTd[3].innerText = rowdata[j].AMOUNT;

					newTd[4] = newTr.insertCell();
					if(rowdata[j].SUM != undefined) {
						newTd[4].innerText = rowdata[j].SUM;
					}
				}

			}

		}
	</script>

</html>